package cz.hanis.android.geography.adapters;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import cz.hanis.android.geography.R;

public class TestTypeSpinnerAdapter extends ArrayAdapter<String> {

	private LayoutInflater inflater;
	
	private String[] names;
	private String[] descriptions;
	private int[] icons;

	public TestTypeSpinnerAdapter(Context context, int textViewResourceId, String[] names, String[] descriptions, int[] icons) {
		super(context, textViewResourceId, names);
		this.names = names;
		this.descriptions = descriptions;
		this.icons = icons;
		inflater = ((Activity) context).getLayoutInflater();		
	}

	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return getCustomView(position, convertView, parent);
	}

	public View getCustomView(int position, View convertView, ViewGroup parent) {

		View row = inflater.inflate(R.layout.test_type_row, parent, false);
		TextView name = (TextView) row.findViewById(R.id.ttr_name);
		name.setText(names[position]);
		
		TextView description = (TextView) row.findViewById(R.id.ttr_description);
		description.setText(descriptions[position]);
		

		ImageView icon = (ImageView) row.findViewById(R.id.ttr_image);
		icon.setImageResource(icons[position]);
		
		return row;
	}
}